package com.example.myapplication

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.binioter.guideview.GuideBuilder
import com.example.myapplication.databinding.FragmentFirstBinding
import com.hqf.guide.NewbieGuide
import com.hqf.guide.model.GuidePage

/**
 * A simple [Fragment] subclass as the default destination in the navigation.
 */
class FirstFragment : Fragment() {

    private var _binding: FragmentFirstBinding? = null

    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        _binding = FragmentFirstBinding.inflate(inflater, container, false)
        return binding.root

    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        binding.buttonFirst.setOnClickListener {
//            findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)

            Toast.makeText(context,"点击事件",Toast.LENGTH_SHORT).show()
        }
        binding.buttonClick.setOnClickListener {
//            findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)

            Toast.makeText(context,"点击事件",Toast.LENGTH_SHORT).show()
        }
//        showGuidView1()

    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }

    private fun showGuideView() {

        val builder =  GuideBuilder()
        builder.setTargetView(binding.buttonFirst)
            .setAlpha(100)
            .setFullingColorId(R.color.pickerview_timebtn_nor)
            .setOverlayTarget(true)
        builder.setOnVisibilityChangedListener(object : GuideBuilder.OnVisibilityChangedListener {

            override fun onShown() {
            }

            override fun onDismiss() {

            }
        });

        builder.addComponent(MainComponent())
        val guide = builder.createGuide()
        guide.show(activity)
    }

    private fun showGuidView1(){

        NewbieGuide.with(this)
            .setLabel("guide1")
            //.setShowCounts(3)//控制次数
            .alwaysShow(true)//总是显示，调试时可以打开
            .addGuidePage(GuidePage.newInstance()
                .addHighLight(binding.buttonFirst)
                .setLayoutRes(R.layout.fragment_first))
            .show();

    }
}